<template>
	<view class="">
		<cu-custom isSetting bgColor="bg-gradual-pink">
			<block slot="content">霁青-TPM</block>
		</cu-custom>
		<scroll-view class="bg-white " scroll-y
			:style="[{height:'calc(100vh - ' + CustomBar + 'px)',position:'relative'}]">
			<view v-if="userInfo.nickName" class="top-name-title flex flex-direction justify-center" style="left: 0;">
				<view class="flex-1 text-center">
					<text class="text-xxl text-bold">欢迎{{userInfo.nickName}}</text>
				</view>
				<view class="flex-1 text-center">
					<text class="text-bold">版本号：{{vesition}}</text>
				</view>
			</view>
			<view class="flex justify-center flex-direction" style="height: 100%;">
				<view class="tack-btm-main text-center margin-top-xl" v-for="(button,bIndex) in buttonArray"
					:key='bIndex'>
					<block>
						<button @tap="menuNavito" :data-name="button.name" :class="['bg-blue','text-white cu-btn']">
							{{button.name}}
						</button>
					</block>
				</view>
			</view>
		</scroll-view>
		<view class="cu-modal" :class="inputModal?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content text-xxl text-bold">设备编号:</view>
					<view class="action" @tap="hideInputModal">
						<text class="icon-close text-red"></text>
					</view>
				</view>
				<view class="padding">
					<view class="solid-bottom flex flex-direction padding-bottom-sm">
						<input style="width: 100%;" type="text" placeholder="请输入" v-model="equipmentNo" />
						<text v-if="inputNoCheck" class="text-sm text-red margin-top-sm">请输入设备编号</text>
					</view>
					<view class="flex justify-center margin-top" style="width: 100%;">
						<button class="cu-btn bg-blue shadow padding-lr-xl" @tap="TPMnavitoUrl">提交</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import helper from '../../common/helper.js';
	export default {
		data() {
			return {
				inputNoCheck: false,
				inputModal: false,
				navitoUrl: '',
				vesition: this.$helper.vesition,
				userInfo: this.$helper.userInfo,
				loginUser: {
					loginName: "SYSSH",
					password: "root123",
					loginType: "NAME_PASSWORD"
				},
				CustomBar: this.CustomBar,
				equipmentNo: '',
				buttonArray: [{
						name: '设备管理'
					}, {
						name: '设备维修列表'
					}, {
						name: '设备保养列表'
					}
					// , {
					// 	name: '设备维修'
					// }, {
					// 	name: '设备保养'
					// },
				]
			}
		},
		mounted() {
			console.log('这里走了没有+++')
			this.getAuth(helper.serviceId)
		},
		onLoad(option) {
			//#ifdef H5
			// var url = window.location.href;
			// console.log(helper.serviceId, '+++')
			// this.getAuth(helper.serviceId)
			//#endif
		},
		onShow() {
			var that = this;
		},

		methods: {
			getAuth(key) {
				console.log('这里走了没有')
				const str = '?serviceId=' + key
				this.$api.getAPI('/auth/api/currentUserPermissions', str).then(res => {
					helper.authList = res.data
					console.log(helper.authList, 'helper.authList')
				})
			},
			TPMnavitoUrl() {
				var that = this;
				if (!that.equipmentNo) {
					that.inputNoCheck = true;
					return false;
				} else {
					that.inputNoCheck = false;
				}
				that.$helper.equipmentNo = that.equipmentNo;
				uni.navigateTo({
					url: that.navitoUrl,
					success() {
						that.hideInputModal();
					}
				});
			},
			showInputModal() {
				var that = this;
				that.inputModal = true;
			},
			hideInputModal() {
				var that = this;
				that.inputModal = false;
				that.equipmentNo = '';
			},


			menuNavito(e) {
				var that = this;
				let name = e.currentTarget.dataset.name;
				let url = ''
				if (name == '设备维修') url = '../index/index'
				if (name == '设备保养') url = '../main/index'
				if (name == '设备维修列表') url = '../repair-list/index'
				if (name == '设备保养列表') url = '../main-list/index'
				if (name == '设备管理') url = '../print-label/index'
				if (url) {
					uni.navigateTo({
						url
					});
				}

			}
		}
	}
</script>

<style>
	.top-name-level {
		position: absolute;
		top: 50rpx;
		left: 25rpx;
		width: 100%;
	}

	.top-name-title {
		position: absolute;
		top: 50rpx;
		left: 0rpx;
		width: 100%;
	}

	.button-show-num {
		position: absolute;
		right: -15rpx;
		top: -15rpx;
		min-width: 40rpx;
		padding: 10rpx;
		height: 40rpx;
		background: red;
		border-radius: 50%;
		font-size: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tack-btm-main>.cu-btn {
		width: 50%;
		height: 100rpx;
		box-shadow: 15rpx 10rpx 20rpx 0rpx rgb(0, 129, 255);
		font-size: 32rpx;
	}
</style>